package com.che.software.testato.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.che.software.testato.business.exception.ActivityDocumentationCreationManagerException;
import com.che.software.testato.business.exception.ActivitySearchManagerException;
import com.che.software.testato.domain.dao.IActivityDAO;
import com.che.software.testato.domain.dao.jdbc.exception.ActivityDocumentationCreationDAOException;
import com.che.software.testato.domain.dao.jdbc.exception.ActivitySearchDAOException;
import com.che.software.testato.domain.entity.Activity;
import com.che.software.testato.domain.entity.ActivityAction;
import com.che.software.testato.domain.entity.ActivityParameter;

/**
 * Manager dedicated to the activities.
 * 
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @copyright Che Software.
 * @license GNU General Public License.
 * @since July, 2011.
 * 
 *        This file is part of Testato.
 * 
 *        Testato is free software: you can redistribute it and/or modify it
 *        under the terms of the GNU General Public License as published by the
 *        Free Software Foundation, either version 3 of the License, or (at your
 *        option) any later version.
 * 
 *        Testato is distributed in the hope that it will be useful, but WITHOUT
 *        ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *        FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 *        for more details.
 * 
 *        You should have received a copy of the GNU General Public License
 *        along with Testato. If not, see <http://www.gnu.org/licenses/>.
 * 
 *        Testato's logo is a creation of Arrioch
 *        (http://arrioch.deviantart.com/) and it's distributed under the terms
 *        of the Creative Commons License.
 */
@Service("activityManager")
public class ActivityManager {

	/**
	 * Constants.
	 */
	private static final Logger LOGGER = Logger.getLogger(ActivityManager.class);

	/**
	 * Members.
	 */
	@Autowired
	private IActivityDAO activityDAO;

	/**
	 * Creates the documentation of an activity from actions and parameters
	 * lists.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param activity the activity to document.
	 * @param actions the actions list.
	 * @param parameters the parameters list.
	 * @since July, 2011.
	 * @throws ActivityDocumentationCreationManagerException if an error occurs
	 *         during the creation.
	 */
	public void createActivityDocumentation(Activity activity, List<ActivityAction> actions, List<ActivityParameter> parameters) throws ActivityDocumentationCreationManagerException {
		LOGGER.debug("createActivityDocumentation(" + activity.getActivityId() + "," + actions.size() + " actions," + parameters.size() + " parameters).");
		try {
			activityDAO.createActivityDocumentation(activity, actions, parameters);
		} catch (ActivityDocumentationCreationDAOException e) {
			throw new ActivityDocumentationCreationManagerException(e);
		}
	}

	/**
	 * Activities to describe search.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @return the resulting object list.
	 * @since July, 2011.
	 * @throws ActivitySearchManagerException if an error occurs during the
	 *         search.
	 */
	public List<Activity> searchActivitiesToDescribe() throws ActivitySearchManagerException {
		LOGGER.debug("searchActivitiesToDescribe().");
		try {
			return activityDAO.searchActivitiesToDescribe();
		} catch (ActivitySearchDAOException e) {
			throw new ActivitySearchManagerException(e);
		}
	}

	/**
	 * Activities to describe search from a parent test case id.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param testCaseId the parent test case id.
	 * @return the resulting object list.
	 * @since July, 2011.
	 * @throws ActivitySearchManagerException
	 */
	public List<Activity> searchActivitiesToDescribeFromTestCaseId(int testCaseId) throws ActivitySearchManagerException {
		LOGGER.debug("searchActivitiesToDescribeFromTestCaseId(" + testCaseId + ").");
		try {
			return activityDAO.searchActivitiesToDescribeFromTestCaseId(testCaseId);
		} catch (ActivitySearchDAOException e) {
			throw new ActivitySearchManagerException(e);
		}
	}

	/**
	 * Getter for the private field value activityDAO.
	 * 
	 * @return the activityDAO field value.
	 */
	public IActivityDAO getActivityDAO() {
		return activityDAO;
	}

	/**
	 * Setting a value to the activityDAO field.
	 * 
	 * @param activityDAO the value to set.
	 */
	public void setActivityDAO(IActivityDAO activityDAO) {
		this.activityDAO = activityDAO;
	}
}